package com.learner.course.repository;


import java.util.*;

import com.learner.pojo.course.Teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ice2020x
 * @Date: 2023/3/9
 * @Description:
 **/
@Repository
public interface TeacherRepository extends JpaRepository<Teacher, String>, JpaSpecificationExecutor<Teacher> {


    /**
     * 根据id列表逻辑删除
     *
     * @param ids 讲师id列表
     */
    @Modifying
    @Transactional(rollbackFor = Exception.class)
    @Query("update Teacher s set s.deleted =true  where s.id in (?1)")
    void deleteBatch(List<String> ids);


    /**
     * 根据id列表真实删除
     *
     * @param ids 讲师id列表
     */
    @Modifying
    @Transactional(rollbackFor = Exception.class)
    @Query("delete from Teacher s where s.id in (?1)")
    void deleteBatchAuthentic(List<String> ids);


    /**
     * 根据名称模糊查询讲师列表 名称字段
     *
     * @param key 讲师名称
     * @return 名称字段
     */
    @Modifying
    @Query(value = "select name from edu_teacher where name like ?1", nativeQuery = true)
    List<Map<String, Object>> findAllCategories(@Param("key") String key);

    /**
     * 根据名字和逻辑删除状态查询讲师列表
     *
     * @param key   讲师名称
     * @param state 讲师状态
     * @return 名称字段
     */
    @Modifying
    @Query(value = "select * from edu_teacher where name like ?1 and is_deleted=?2", nativeQuery = true)
    List<Teacher> findAllTeachersByName(@Param("key") String key, @Param("state") Integer state);

    /**
     * 根据名字和状态查询讲师列表
     *
     * @param state 讲师状态
     * @return 名称字段
     */
    @Modifying
    @Query(value = "select * from edu_teacher where  is_deleted=?1", nativeQuery = true)
    List<Teacher> findAllTeachersByState(@Param("state") Integer state);
}
